package com.voxel.sense.infomsg.module.task.overdue;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.com.common.view.EmptyView;
import com.example.com.common.view.recycler.RecyclerAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.interfaces.listener.OnCustomItemClickListener;
import com.voxel.sense.infomsg.module.common.VRecyclerActivity;
import com.voxel.sense.infomsg.module.task.list.TaskListAdapter;
import com.voxel.sense.infomsg.module.task.list.TaskListContract;
import com.voxel.sense.infomsg.module.task.list.TaskListPresenter;
import com.voxel.sense.infomsg.view.decoration.LinearItemDecoration;
import com.voxel.sense.infomsg.view.titlebar.CommonTitleBar;

import butterknife.BindView;
import cyy.example.com.facotry.model.api.response.TaskInfoEntity;

/**
 * @author ChenYiYao
 * @date 2018/5/14
 * des : 任务列表view
 */
public class OverdueTaskListActivity extends VRecyclerActivity<TaskListContract.Presenter, TaskInfoEntity.ObBean>
        implements TaskListContract.View<TaskInfoEntity.ObBean> {
    @BindView(R.id.titlebar)
    CommonTitleBar titlebar;
    @BindView(R.id.recycle_view)
    RecyclerView recycle_view;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refresh_layout;
    @BindView(R.id.empty_view)
    EmptyView empty_view;


    private TaskListAdapter mAdapter;


    public static void show(Context context) {
        context.startActivity(new Intent(context, OverdueTaskListActivity.class));
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_overdue_task;
    }

    @Override
    protected TaskListPresenter initPresenter() {
        return new TaskListPresenter(this);
    }

    @Override
    protected void initData() {
        super.initData();

        titlebar.setTitleText("失败任务");

        recycle_view.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new TaskListAdapter();
        LinearItemDecoration linearItemDecoration = new LinearItemDecoration(R.drawable.recycle_divider_10dp);
        linearItemDecoration.setDrawFirstItem(true).setDrawVerticalModelLeftAndRightBorder(true,true);
        recycle_view.addItemDecoration(linearItemDecoration);
        recycle_view.setAdapter(mAdapter);
        empty_view.triggerOk();
        empty_view.bind(refresh_layout);
        refresh_layout.autoRefresh();//第一次进入触发自动刷新
    }

    @Override
    protected void initEven() {
        super.initEven();

        refresh_layout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                mPresenter.doLoadData();
            }
        });


        mAdapter.setLocationClickEvent(new OnCustomItemClickListener() {
            @Override
            public void onClick(View view, Object data, int position) {

            }

        });


    }


    @Override
    public RecyclerAdapter<TaskInfoEntity.ObBean> getRecyclerViewAdapter() {
        return mAdapter;
    }


    @Override
    public void onRefreshTaskStatu(String statu, String taskId) {

    }
}
